package com.oa.official.controller;


import com.oa.official.service.SysMenuService;
import com.oa.official.entity.system.SysMenu;
import com.oa.official.response.Result;
import com.oa.official.vo.system.AssginMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author LQ
 * @since 2024-03-05
 */
@Api(tags = "菜单管理")
@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    @ApiOperation(value = "获取菜单树形结构")
    @GetMapping("/findNodes")
    public Result findNodes() {
        return sysMenuService.findNodes();
    }

    @ApiOperation(value = "新增菜单")
    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu) {
        return sysMenuService.save(sysMenu);
    }

    @ApiOperation(value = "修改菜单")
    @PutMapping("/update")
    public Result updateById(@RequestBody SysMenu sysMenu) {
        return sysMenuService.updateById(sysMenu);
    }

    @ApiOperation(value = "删除菜单")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable(value = "id") Long menuId) {
        return sysMenuService.removeById(menuId);
    }



    @ApiOperation(value = "查看某个角色的权限列表")
    @GetMapping("/toAssign/{roleId}")
    public Result toAssign(@PathVariable Long roleId) {
        return sysMenuService.findSysMenuByRoleId(roleId);
    }

    @ApiOperation(value = "给角色分配权限")
    @PostMapping("/doAssign")
    public Result doAssign(@RequestBody AssginMenuVo assginMenuVo) {
        return sysMenuService.doAssign(assginMenuVo);
    }

}

